home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmigaPlus / Tools / Development / stunnel-4.04 / share / doc / stunnel / examples / ca.pl < prev    next >
Encoding:
Perl Script  |  2003-02-08  |  1.8 KB  |  66 lines

  1. #!/usr/bin/perl
  2.  
  3. $config   = "/var/openssl/openssl.cnf";
  4. $capath   = "/usr/bin/openssl ca";
  5. $certpass = "mypassword";
  6. $tempca   = "/tmp/ssl/cli".rand 10000;
  7. $tempout  = "/tmp/ssl/certtmp".rand 10000;
  8. $caout    = "/tmp/ssl/certout.txt";
  9. $CAcert   = "/var/openssl/localCA/cacert.pem";
  10. $spkac      = "";
  11.  
  12. &ReadForm;
  13.  
  14. $spkac = $FIELDS{'SPKAC'};
  15. $spkac =~ s/\n//g;
  16.  
  17. open(TEMPCE,">$tempca") || die &Error;
  18. print TEMPCE "C = $FIELDS{'country'}\n";
  19. print TEMPCE "ST = $FIELDS{'state'}\n";
  20. print TEMPCE "O = $FIELDS{'organization'}\n";
  21. print TEMPCE "Email = $FIELDS{'email'}\n";
  22. print TEMPCE "CN = $FIELDS{'who'}\n";
  23. print TEMPCE "SPKAC = $spkac\n";
  24. close(TEMPCE);                         
  25.  
  26. system("$capath -batch -config $config -spkac $tempca -out $tempout -key $certpass -cert $CAcert>> $caout 2>&1"); 
  27. open(CERT,"$tempout") || die &Error;
  28. @certificate = <CERT>;
  29. close(CERT);
  30.  
  31. #system("rm -f $tempca");
  32. #system("rm -f $tempout");
  33.  
  34. print "Content-type: application/x-x509-user-cert\n\n";
  35. print @certificate;
  36.  
  37. ##############################################################
  38. ####
  39. ####     Procedures
  40. ####
  41.  
  42. sub ReadForm {
  43.  
  44.    if ($ENV{'REQUEST_METHOD'} eq 'GET') {
  45.       @pairs = split(/&/, $ENV{'QUERY_STRING'});
  46.    }
  47.    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
  48.       read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  49.       @pairs = split(/&/, $buffer);
  50.    }
  51.    foreach $pair (@pairs) {
  52.       ($name, $value) = split(/=/, $pair);
  53.       $name =~ tr/+/ /;
  54.       $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  55.       $value =~ tr/+/ /;
  56.       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  57.       $value =~ s/<!--(.|\n)*-->//g;
  58.       $FIELDS{$name} = $value;
  59.       }
  60. }
  61.  
  62. sub Error {
  63.     print "Content-type: text/html\n\n";
  64.     print "<P><P><center><H1>Cant open file</H1></center>\n";
  65. }
  66.